//index.js
var iFDU = require('../../utils/iFDU.js');
var app = getApp()
Page({
  data: {
    config: app.config,
    globalData: app.globalData,
    swiperDatas: [],
    swiper: {
      indicatorDots: true,
      autoplay: true,
      interval: 2000,
      duration: 500,
    },
    service: [{
      name: '专属定制',
      desc: '逸见服饰为您提供极简便捷的专属定制体验，让您轻松玩转私人定制！',
      icon: '../../images/common/custom.png'
    }, {
      name: '免费绣字',
      desc: '我们免费为您提供个性化的袖口刺绣服务，让您的衬衫与众不同！',
      icon: '../../images/common/word.png'
    }, {
      name: '身型保险计划',
      desc: '逸见服饰独家创新的极致售后保障！身材有变化？我们来赔付！',
      icon: '../../images/common/security.png'
    }, {
      name: '免费修改',
      desc: '衬衫不够合体？我们负责为您修改！您满意，我们更开心！',
      icon: '../../images/common/modify.png'
    }],
    newProducts: [],
    recommendProducts: [],
    currentRecommendIndex: 0,
    recommendPreviewImage: '',
    recommend: {
      image: '../../sample-images/swiper-sample.jpg',
      items: [{
        icon: '../../sample-images/swiper-sample.jpg',
        desc: '产品介绍产品介绍产品介绍产品介绍产品介绍产品介绍',
        price: 123
      }, {
        icon: '../../sample-images/swiper-sample.jpg',
        desc: '产品介绍',
        price: 123
      }, {
        icon: '../../sample-images/swiper-sample.jpg',
        desc: '产品介绍',
        price: 123
      }, {
        icon: '../../sample-images/swiper-sample.jpg',
        desc: '产品介绍',
        price: 123
      }, {
        icon: '../../sample-images/swiper-sample.jpg',
        desc: '产品介绍',
        price: 123
      }]
    },
    modalStatus: false,
    userInfo: {}
  },
  showServiceDetail: function () {
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
      modalStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 200)
  },
  hideServiceDetail: function () {
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        modalStatus: false
      })
    }.bind(this), 200)
  },
  showGoodsDetail: function (e) {
    wx.navigateTo({
      url: '../goods-item/goods-item?goodsId=' + e.currentTarget.dataset.id,
    })
  },
  scrollNew: function (e) {
    console.log(e);
  },
  showGoodsList: function (e) {
    var title = e.currentTarget.dataset.title;
    wx.navigateTo({
      url: '../goods-list/goods-list?groupId=' + e.currentTarget.dataset.id + '&title=' + title,
    })
  },

  showDetail: function (e) {
    var id = e.currentTarget.dataset.id;
    var type = e.currentTarget.dataset.type;
    if (type == 1) {
      wx.navigateTo({
        url: '../goods-item/goods-item?goodsId=' + e.currentTarget.dataset.id,
      })
    } else if (type == 5) {
      wx.navigateTo({
        url: '../goods-list/goods-list?groupId=' + e.currentTarget.dataset.id,
      })
    } else if (type == 4) {
      wx.navigateTo({
        url: '../special-subject/special-subject?specialId=' + e.currentTarget.dataset.id,
      })
    } else if (type == 3) {
      wx.navigateTo({
        url: id,
      })
    }
  },

  onLoad: function (options) {
    var that = this;
    var channelId = options.channelId;
    var param = {};
    if (channelId) {
      param['channelId'] = channelId;
    }
    app.getUserInfo(function (globalData) {
      that.setData({
        globalData: globalData
      });

      iFDU.api.doGet(
        'carousel/getCarouselList',
        {
          userId: globalData.userId,
          iscarousel: 1
        },
        function (data) {
          that.setData({
            swiperDatas: data
          })
        }
      );

      iFDU.api.doGet(
        'carousel/getCarouselList',
        {
          userId: globalData.userId,
          iscarousel: 0
        },
        function (data) {
          that.setData({
            newProducts: data
          })
        }
      );

      iFDU.api.doGet(
        'product/getGroupList',
        {
          userId: globalData.userId,
        },
        function (data) {
          that.setData({
            recommendProducts: data
          })
        }
      );
    }, channelId ? param : undefined);
  },

  onShow: function () {
    
  },

  onShareAppMessage: function (res) {
    var that = this;
    return {
      title: '爱上衬衫，从「逸见」开始…',
      imageUrl: 'http://s.i-fdu.com/runto/wxa/s/yjshare.jpeg',
      path: 'pages/home/home',
      success: function (res) {
      },
      fail: function (res) {
      }
    }
  }
})
